# import redis
# #
# # #定义地址和端口
# # host = '127.0.0.1'
# # port = 6379
# #
# # #建立redis连接
# # r = redis.Redis(host=host,port=port)
# #
# # #声明一个值
# # r.set('test','123')
# #
# # #取值
# # code = r.get('test')
# #
# # #转码
# # code = code.decode('utf-8')
# #
# # print(code)

import redis

#定义host和端口

host = '127.0.0.1'
# host = '192.168.99.100'


port = 6379
# port = 6380

r = redis.Redis(host=host,port=port)

#有序集合
# r.zadd('myrank',{'car':100})
# r.zadd('myrank',{'phone':150})
# r.delete("myrank")

#修改操作
# newscore = r.zincrby('myrank',300,'car')
# print(newscore)
#遍历有序集合
# print(r.zrange('myrank',0,-1,desc=True,withscores=True))

# r.expire('myrank123',60)
#ttl关键字，查看过期时间
# print(r.ttl('myrank123'))


#赋值
# myrank = r.zrange('myrank',0,-1,desc=True,withscores=True)
# #取值
# print(str(myrank[0][0],'utf8'))
# print(float(myrank[0][1]))


# r.set("789789",123)
#10s以内有效 恶意评论
# r.expire('789789',10)
# print(r.ttl('789789'))
# print(r.get('789789'))

# r.set("qwezxc",123123)
# r.expire('qwezxc',3600)
print(r.ttl('qwezxc'))
print(3600-r.ttl('qwezxc'))

# r.set('test123','test123')
"""
myredis = r.get('321')
r.sadd('testset','爆款')
r.sadd('testset','修身')

myset = r.smembers('testset')
myset = list(myset)
mytag = myset[0].decode("utf-8")
# 转码
# myredis = myredis.decode("utf8")

r.delete('testset')

# print(myredis)
print(mytag)

"""
# list的使用
# r.lpush("testlist",1)
# print(r.llen('testlist'))

#key 开始下标（一般为0），结束下标（长度）
# mylist = r.lrange('testlist',0,r.llen('testlist'))